package com.nbufe.observer.demo1;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Zan
 * @Create 2024/5/27 8:28
 * @ClassName: ConcreteTeamFormationAlliance
 * @Description : TODO 请用一句话描述该类的功能
 */
public class ConcreteTeamFormationAlliance implements TeamFormationAlliance{

    private List<Observer> playerList = new ArrayList<>();

    private String allyName;

    public ConcreteTeamFormationAlliance(String allyName) {
        this.allyName = allyName;
    }

    @Override
    public void addObserver(Observer observer) {
        System.out.println(observer.getName() + "加入了" + allyName);
        playerList.add(observer);
    }

    @Override
    public void delObserver(Observer observer) {
        playerList.remove(observer);
    }

    @Override
    public void notify(String name) {
        // 对所有联盟成员(除了求救的人)进行推送求救讯息
        for (Observer observer : playerList) {
            if (!name.equals(observer.getName())) {
                System.out.println(allyName + "已向联盟成员" + observer.getName() + "发送通知");
                observer.help();
            }
        }
    }
}
